import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_syt/domain/epidemic/choose_box.dart';
import 'package:flutter_syt/domain/widgets/common_dialog.dart';
import 'package:flutter_syt/domain/widgets/custom_dialog.dart';
import 'package:flutter_syt/generated/l10n.dart';
import 'package:flutter_syt/theme/theme_color.dart';
import 'package:flutter_syt/utils/click_utils.dart';

class MultiplePickerItemEntity {
  late String name;
  late String placeholder;
  late String defaultValue;
  late List option;
  late Function updateData;

  MultiplePickerItemEntity(this.name, this.placeholder, this.defaultValue,
      this.option, this.updateData);
}

class MultiplePicker extends StatefulWidget {
  final MultiplePickerItemEntity entity;
  const MultiplePicker(this.entity, {Key? key}) : super(key: key);
  @override
  State<StatefulWidget> createState() => _MultiplePickerState();
}

class _MultiplePickerState extends State<MultiplePicker> {
  String chooseValue = '';
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    ItemEntity pickerData = ItemEntity(
      widget.entity.defaultValue,
      widget.entity.option,
      (value) {
        chooseValue = value.join(' ');
      },
    );
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          widget.entity.name,
          style: TextStyle(
            color: ThemeColor.colorBlack60,
            fontSize: 16,
          ),
        ),
        GestureDetector(
          onTap: ClickUtils.debounce(() {
            showCommonDialog(
              context,
              DialogEntity(
                '请选择',
                ChooseBox(pickerData),
                () => {
                  Navigator.of(context).pop(),
                },
                () {
                  Navigator.of(context).pop();
                  widget.entity.updateData(chooseValue);
                },
                cancelText: S.of(context).cancel,
                okText: S.of(context).save,
              ),
            );
          }),
          child: Container(
            padding: EdgeInsets.only(top: 6, bottom: 10),
            decoration: BoxDecoration(
              border: Border(
                bottom: BorderSide(width: 2, color: Color(0xffc6c6c6)),
              ),
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  widget.entity.defaultValue != ''
                      ? widget.entity.defaultValue
                      : widget.entity.placeholder,
                  style: TextStyle(
                    color: widget.entity.defaultValue != ''
                        ? ThemeColor.colorBlack80
                        : ThemeColor.colorBlack30,
                    fontSize: 16,
                  ),
                ),
                Icon(
                  Icons.chevron_right,
                  color: ThemeColor.colorBlack60,
                ),
              ],
            ),
          ),
        ),
      ],
    );
  }
}
